<?php
/**
 * User: 魔十七
 * Date: 2020/11/12
 * Time: 8:30
 */

namespace Samecity\Model;

use Think\Model;

class CateringAuditModel extends Model
{
    /**
     * 当前用户是否有(审核)记录
     * @param $uid  用户ID
     * */
    public function getAuditUid($uid)
    {
        $where['uid'] = $uid;
        $data = M('catering_audit')->where($where)->order('id desc')->find();
        return $data;
    }

    /**
     * 发起审核
     * @param $array    arr数据
     * @param $type     失败/驳回(默认是'')
     * */
    public function getAuditAdd($array, $type)
    {
        $array['audit_type']    = 0;
        $array['create_time']   = time();
        $array['day']           = 0;
        $array['bz']            = '正在审核中,请耐心等待!';

        if ($type != ''){
            $data = M('catering_audit')->add($array);
            if ($data){
                /* 重复审核,生成日志 */
                $log['log_type']    = $type;
                $log['log_time']    = time();
                $log['log_uId']     = $array['uid'];
                if ($type == '2'){
                    $log['log_msg']  = "审核失败记录";
                }elseif ($type == '3') {
                    $log['log_msg']  = "审核驳回记录";
                }
                M('catering_audit_log')->add($log);
            }
        } else{
            $data = M('catering_audit')->add($array);
        }
        return $data;
    }
}